<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        
        html,
        body {
            width: 100%;
            height: 100%;
        }
        
        #wrap {
            width: 100%;
            height: 40px;
            background-color: #00214F;
            margin-top: 50px;
        }
        
        #root {
            width: 1000px;
            height: 100%;
            margin: 0 auto;
            /*background-color: salmon;*/
            position: relative;
        }
        
        #slider {
            width: 60px;
            height: 40px;
            background-color: red;
            position: absolute;
            transition: all 0.3s linear;
        }
        
        #title {
            list-style: none;
            position: absolute;
        }
        
        #title li {
            width: 60px;
            height: 40px;
            line-height: 40px;
            float: left;
            margin-right: 10px;
            color: white;
            font-weight: bold;
            text-align: center;
        }
        
        #title li:first-child {
            background-color: red;
        }
    </style>
</head>

<body>
    <div id="wrap">
        <div id="root">
            <!--滑块-->
            <div id="slider"></div>
            <!--标题-->
            <ul id="title">
                <li>首页</li>
                <li>国内</li>
                <li>国际</li>
                <li>军事</li>
                <li>财经</li>
                <li>娱乐</li>
                <li>体育</li>
                <li>互联网</li>
                <li>科技</li>
                <li>游戏</li>
                <li>女人</li>
                <li>汽车</li>
                <li>房产</li>
            </ul>

        </div>
    </div>


</body>

</html>
<script src="./jquery-3.4.1.min.js"></script>
<script>
    var dian = 0;
    $("#title li").mouseenter(function() {
        var index = $(this).index();
        $("#slider").css({
            left: index * 70
        })
    });
    $("#title").mouseleave(function() {
        $("#slider").css({
            left: dian * 70
        })
    });
    $("#title li").click(function() {
        dian = $(this).index();
        $(this).css({
            backgroundColor: "red"
        });
        $(this).siblings().css({
            backgroundColor: "transparent"
        });
    })
</script>